<?php
namespace app\admin\controller;


class Log extends Common
{
	/**
	 * 后台日志
	 * @return mixed
	 * @throws \think\Exception
	 */
	public function admin_log(){
		$where['id'] = array('gt',0);

		$page=Request()->param('page');
		$size=Request()->param('size');
		//分页
		$way=Request()->param('way');
		//请求地址
		$day=Request()->param('day');
		//日期
		if($way!=''){
			$where['a.way']=array('like','%'.$way.'%');
		}
		if($day!=''){
			$where['a.time']=array('like','%'.$day.'%');
		}
		if($page<1){
			$page=1;
		}
		if($size<15){
			$size=15;
		}
		$now=($page-1)*$size;
		$data=db('admin_log a')
			->where($where)
			->limit("$now,$size")
			->order("a.id desc")
			->select();
		$count=db('admin_log a')
			->where($where)
			->count();
		$page_str=page($page,$size,$count,count($data));//分页

		$this->assign('way',$way);
		$this->assign('day',$day);
		$this->assign('data',$data);
		$this->assign('count',$count);
		$this->assign('page',$page);
		$this->assign('size',$size);
		$this->assign('page_str',$page_str);
		return $this->fetch();
	}
    /**
     * 后台日志
     * @return mixed
     * @throws \think\Exception
     */
    public function api_log(){
        $where['id'] = array('gt',0);

        $page=Request()->param('page');
        $size=Request()->param('size');
        //分页
        $way=Request()->param('way');
        //请求地址
        $uid=Request()->param('uid');
        //用户id
        $mobile=Request()->param('mobile');
        //用户id
        $start_time=strtotime(Request()->param('start_time'));
        $end_time=strtotime(Request()->param('end_time'));
        if($way!=''){
            $where['a.method_name']=array('like','%'.$way.'%');
        }
        if($uid>0){
            $where['a.uid']=array('like','%'.$uid.'%');
        }
        if($mobile>0){
            $where['b.u_mobile']=array('like','%'.$mobile.'%');
        }
        if($page<1){
            $page=1;
        }
        if($size<15){
            $size=15;
        }
        $where_time=array(array('gt',0),array('gt',0));
        if($start_time>0){
            $where_time[]=array('egt',$start_time);
        }else{
            $start_time='';
        }
        if($end_time>0){
            $where_time[]=array('elt',$end_time);
        }else{
            $end_time='';
        }
        $where['a.create_time']=$where_time;
        $now=($page-1)*$size;
        $data=db('api_log a')
            ->field("a.*,b.u_mobile,b.u_real_name,b.u_store_name")
            ->join('fr_user b', 'a.uid = b.u_id', 'left')
            ->where($where)
            ->limit("$now,$size")
            ->order("a.id desc")
            ->select();
        $count=db('api_log a')
            ->join('fr_user b', 'a.uid = b.u_id', 'left')
            ->where($where)
            ->count();
        $page_str=page($page,$size,$count,count($data));//分页
        $this->assign('uid',$uid);
        $this->assign('mobile',$mobile);
        $this->assign('way',$way);
        $this->assign('start_time',$start_time);
        $this->assign('end_time',$end_time);
        $this->assign('data',$data);
        $this->assign('count',$count);
        $this->assign('page',$page);
        $this->assign('size',$size);
        $this->assign('page_str',$page_str);
        return $this->fetch();
    }

}